﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;
namespace project
{
    public partial class AddStudent : UIForm
    {
        public AddStudent()
        {
            InitializeComponent();
        }

        private void ClearTextBox()
        {
            uiTextBox1.Text = null;
            uiTextBox2.Text = null;
            uiTextBox3.Text = null;
            uiTextBox4.Text = null;
            uiTextBox5.Text = null;
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            //确定
            string id = uiTextBox1.Text;
            string pwd = uiTextBox2.Text;
            string name = uiTextBox3.Text;
            string dept = uiTextBox4.Text;
            string phone = uiTextBox5.Text;
            string sqlstr = $"insert into student(number,pwd,name,dept,phone_number) " +
                $" values('{id}','{pwd}','{name}','{dept}','{phone}');";

            if (string.IsNullOrEmpty(id) ||
                string.IsNullOrEmpty(pwd)||
                string.IsNullOrEmpty(name)||
                string.IsNullOrEmpty(dept)||
                string.IsNullOrEmpty(phone))
            {
                MessageBox.Show("存在空数据，请检查后再添加", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int reslut = SqlHelper.ExecuteNonQuery(sqlstr);
            if (reslut == 1)
            {

                MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                ClearTextBox();
            }
            else
            {
                MessageBox.Show("添加失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        

        }

        private void AddStudent_Load(object sender, EventArgs e)
        {
        }

        private void uiButton2_Click(object sender, EventArgs e)
        {
            //返回
            this.Close();
        }
    }
}

